package leraning.httpUrlConnection;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpURLConnection4 {
	public static void main(String[] args) {
		String path = "http://www.jsssyjxh.com.cn/2012-01/31/xin_533010931131687528961.jpg";
		HttpURLConnection conn = null;
		try {
            URL url=new URL(path);
            conn=(HttpURLConnection) url.openConnection();
            BufferedInputStream is=new BufferedInputStream(conn.getInputStream());
            BufferedOutputStream os=new BufferedOutputStream(new FileOutputStream("img/img5.jpg"));
            byte[] b=new byte[1024];
            int len=0;
            while((len=is.read(b))!=-1){
            	os.write(b, 0, len);
            	os.flush();
            }
            System.out.println("finished");
            is.close();
            os.close();
            conn.disconnect();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
